#!/bin/sh
#
# 部署 Nacos
#

version=2.1.0

# 1 代表首次部署
if [[ $1 == '1' ]]; then
  cd ~
  mkdir deploy
  cd deploy

  ## 太慢了
  # wget https://github.com/alibaba/nacos/releases/download/2.1.0/nacos-server-2.1.0.tar.gz
  # tar -xvf nacos-server-2.1.0.tar.gz
  # cd nacos/bin

  git clone https://github.com/alibaba/nacos.git
  cd nacos/
  mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U
  mv distribution/target/nacos-server-${version}/nacos /usr/local/nacos
  cd /usr/local/nacos/bin
  sh startup.sh -m standalone

# 2 代表关闭 Nacos
elif [[ $1 == '2' ]]; then
  cd /usr/local/nacos/bin
  sh shutdown.sh

# 仅启动
else
  cd /usr/local/nacos/bin
  sh startup.sh -m standalone
fi

echo "------------ 部署完成 ------------"